package com.javaex.book.resolver;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.servlet.ServletRequestContext;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * 重写CommonsMultipartResolver中的isMultipart方法，实现PUT请求上传文件
 *
 * @author 黄星琦
 * @Date 2022年4月24日
 */
public class CustomMultipartResolver extends CommonsMultipartResolver {

	@Override
	public boolean isMultipart(HttpServletRequest request) {
		if (RequestMethod.POST.toString().equalsIgnoreCase(request.getMethod()) 
				|| RequestMethod.PUT.toString().equalsIgnoreCase(request.getMethod())) {
			return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
		}
		return false;
	}
}
